package com.sh.config;

import com.sh.common.enums.OssTypeEnum;
import com.sh.service.IOSSService;
import com.sh.service.impl.AliOSSService;
import com.sh.service.impl.MinioService;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Getter
@Configuration
public class OssClientConfig {

    @Value("${oss.type}")
    private String resourceType;

    @Value("${oss.endpoint}")
    private String endpoint;

    @Value("${oss.bucket}")
    private String bucket;

    @Value("${oss.accessKey}")
    private String accessKey;

    @Value("${oss.secretKey}")
    private String secretKey;

    @Value("${oss.signExpires}")
    private Integer signExpires;

    @Bean
    public IOSSService ossService() {
        if (OssTypeEnum.MINIO.getCode().equals(getResourceType())) {
            return new MinioService(this);
        } else if (OssTypeEnum.ALI_OSS.getCode().equals(getResourceType())) {
            return new AliOSSService(this);
        } else {
            log.warn("不支持的对象存储类型:{}", getResourceType());
            return null;
        }
    }

}
